package cn.lupin.service.impl;

import cn.lupin.mapper.VideosMapper;
import cn.lupin.pojo.Users;
import cn.lupin.pojo.UsersExample;
import cn.lupin.pojo.Videos;
import cn.lupin.pojo.VideosExample;
import cn.lupin.service.VideoService;
import cn.lupin.utils.PagedResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VideoServiceImpl implements VideoService {

    @Autowired
    private VideosMapper videosMapper;

    @Override
    public void updateVideoStatus(String videoId, Integer status) {

        Videos video = new Videos();
        video.setId(videoId);
        video.setStatus(status);
        videosMapper.updateByPrimaryKeySelective(video);
    }

    @Override
    public PagedResult queryVideoList(Videos video, Integer page, Integer pageSize) {

        String videoDesc = video.getVideoDesc();
        String userNickname = video.getUserNickname();
        String audioName = video.getAudioName();

        PageHelper.startPage(page, pageSize);

        List<Videos> videoList = videosMapper.selectVideoList(videoDesc, userNickname, audioName);

        PageInfo<Videos> pageList = new PageInfo<>(videoList);

        PagedResult grid = new PagedResult();
        grid.setTotal(pageList.getPages());
        grid.setRows(videoList);
        grid.setPage(page);
        grid.setRecords(pageList.getTotal());

        return grid;
    }
}
